<style type="text/css">
.layui-table-cell{padding:0px 10px;}
.layui-table-view .layui-table td, .layui-table-view .layui-table th{padding:10px 0px;border-bottom:2px dotted #ccc;}
</style><!--.layui-table-cell{padding:0px 0px;}-->
<div class="fixed-bar">
<form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search" >
	<div class="layui-form-item" style="margin-bottom:0px;">
		<div class="layui-inline">
            <label class="layui-form-label">SKU</label>
            <div class="layui-input-inline">
                <input type="text" name="sku" lay-verify="" placeholder="输入SKU" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="padding:7px 5px;">订单号(优先)</label>
            <div class="layui-input-inline" style="width:150px;">
                <input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
			<label class="layui-form-label">生产工厂</label>
			<div class="layui-input-inline">
				{:Form::select('factory_id', '', $factoryKV, '', '')}
			</div>
		</div>
        <div class="layui-inline">
			<label class="layui-form-label">工段</label>
			<div class="layui-input-inline" style="width:140px;">
				{:Form::select('process_stage', '', $process_stages, '', '')}
			</div>
		</div>
        <div class="layui-inline">
            <label class="layui-form-label" style="padding:7px 5px;">工价</label>
            <div class="layui-input-inline" style="width:140px;">
                <input type="text" name="process_price" lay-verify="" placeholder="输入工价" class="layui-input">
            </div>
        </div>
        
		<div class="layui-inline">
			<button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
		</div>
	</div>
	</form>
</div>

<table id="dataTable"></table>

{include file="system@block/layui" /}


<script type="text/html" id="changeLogTpl">
	{{# for(var i in d.processStage){
		var height=28,cols=d.processStageCounts[i],update_time='';
		if(cols!=undefined){height=height*cols['stagecount'];}
	}}
    	<div style="line-height:{{height}}px">
			<a href="{:url('processPriceLog')}?sku={{ d.sku }}&stage={{i}}" title="修改日志" hisi-data="{width: '760px', height: '400px'}" class="hisi-iframe layui-btn layui-btn-xs layui-btn-normale">修改日志</a>
		</div>
	{{# } }}
</script>
<script type="text/html" id="picTpl">
    <img src="{{ d.ori_pic }}" class="lay-pic">
</script>

<script type="text/html" id="processNameTpl">
	{{# for(var i in d.processStage){
		var height=28,cols=d.processStageCounts[i],update_time='';
		if(cols!=undefined){height=height*cols['stagecount'];}
	}}
    	<div style="{{#if(cols==undefined){}}height:28px; {{# } }}border-bottom:1px solid #ddd;">
			{{# 
			if(cols!=undefined){
				for(var index in d.processPriceInfo[i]){ }}
					{{d.processPriceInfo[i][index].process_name }}<br />
				{{# }
			}
			}}
		</div>
	{{# } }}
</script>
<script type="text/html" id="processPriceTpl">
	{{# for(var i in d.processStage){
		var height=28,cols=d.processStageCounts[i],update_time='';
		if(cols!=undefined){height=height*cols['stagecount'];}
	}}
    	<div style="{{#if(cols==undefined){}}height:28px; {{# } }}border-bottom:1px solid #ddd;">
			{{# 
			if(cols!=undefined){
				for(var index in d.processPriceInfo[i]){ }}
					{{d.processPriceInfo[i][index].process_price }}<br />
				{{# }
			}
			}}
		</div>
	{{# } }}
</script>
<script type="text/html" id="processStageTpl">
	{{# for(var i in d.processStage){
	var height=28,cols=d.processStageCounts[i];
		if(cols!=undefined){height=height*cols['stagecount'];}
	}}
    	<div style="line-height:{{height}}px;border-bottom:1px solid #ddd;">{{d.processStage[i]}} </div>
	{{# } }}
</script>
<script type="text/html" id="buttonTpl">
	{{# for(var i in d.processStage){
		var bgclassList=['','layui-bg-blue','layui-bg-orange','layui-bg-green'];
		var height=28,cols=d.processStageCounts[i],update_time='';
		if(cols!=undefined){height=height*cols['stagecount'];}
	}}
    	<div style="line-height:{{height}}px;height:{{height}}px">
		{{# if(d.search_processstage=='' || d.search_processstage==i){ }}
		<a href="{:url('editProcessPrice')}?sku={{ d.sku }}&stage={{i}}" title="设置{{d.processStage[i]}}工价" hisi-data="{width: '660px', height: '360px'}"
		 class="hisi-iframe layui-btn layui-btn-xs {{bgclassList[i]}}">设置{{d.processStage[i]}}工价</a>
		 {{# } }}
		</div>
	{{# } }}
</script>

<script type="text/html" id="upJpTpl">
	{{# 
		var upload_jp_time='',update_gold_state='未同步';
		if(d.upload_jp_time>0){update_gold_state='<strong>已同步</strong>';upload_jp_time=layui.util.toDateString(d['upload_jp_time'] * 1000, 'yyyy-MM-dd HH:mm');}
	}}
    	<div>
		{{update_gold_state}}  
		<br />
		{{upload_jp_time}}  
		</div>
</script>
<script type="text/html" id="updateTimeTpl">
	{{# for(var i in d.processStage){
		var height=28,cols=d.processStageCounts[i],update_time='';
		if(cols!=undefined){height=height*cols['stagecount'];update_time=layui.util.toDateString(cols['update_time'] * 1000, 'yyyy-MM-dd HH:mm');}
	}}
    	<div style="line-height:{{height}}px;" >
		&nbsp;{{update_time}}
		</div>
	{{# } }}
</script>

<script type="text/javascript">
    layui.use(['table','tool'], function() {
        var table = layui.table;
		var $ = layui.jquery;
        var opTable=table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                {field: 'id', title: '编号', sort: true}
                ,{field: 'pic', title: '图片',templet:'#picTpl'}
                ,{field: 'sku', title: 'SKU',width:160,templet:function(d){return '<span class="copy-item">'+d.sku+'</span>'}}
				,{field: 'cost', title: 'MES加工费(含倍率)',width:146}
				,{field: 'sku_process_price', title: '工厂总单价'}
                ,{field: 'processPre', title: '单价占比',templet:function(d){return ''+d.processPre+'%'}}
				,{field: 'sixian_price', title: '工序',templet:'#processNameTpl'}
                ,{field: 'zhuanji_price', title: '工价',templet:'#processPriceTpl'}
                ,{field: 'process', title: '工段',templet:'#processStageTpl'}
                //,{field: 'field2', title: '特殊工艺'}
				,{field: 'update_time', title: '更新时间',templet:'#updateTimeTpl',width:160}
				,{field: 'update_time', title: '同步金鹏状态/日期',templet:'#upJpTpl',width:160}
                ,{field: 'process', title: '操作',templet:'#buttonTpl'}
				,{field: 'field1', title: '修改日志',templet:'#changeLogTpl'}
            ]]
        });
		
		// 刷新当前页
        window.reloadTable = function () {
            var that = $("#hisi-table-search-optable"),
                arr = that.serializeArray(),
                where = new Array(),
                dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
                currPage = 1, //$(".layui-laypage-em").next().html()
                options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:currPage}};
            for(var i in arr) {
                where[arr[i].name] = arr[i].value;
            }

            options.url = that.attr('action');
            options.where = where;

            opTable.reload(options);
            return false;
        }
    });
</script>